﻿#include "ssBillboardMaterial.h"
#include "../camera/ssCamera.h"
#include "../ssTransform.h"

namespace StarSeeker
{

ssBillboardMaterial::ssBillboardMaterial()
{
}

ssBillboardMaterial::~ssBillboardMaterial()
{
}

void ssBillboardMaterial::SetShaderUniform()
{
	if (m_pShader)
	{
		m_shaderCamera.Use(m_pShader, ssCamera::s_currentCamera->GetProjMatrix().m, 4);
		m_shaderView.Use(m_pShader, ssCamera::s_currentCamera->GetViewMatrix().m, 4);

		m_matBillBoard = ssCamera::s_currentCamera->GetViewMatrix();
		m_matBillBoard._41 = m_matBillBoard._42 = m_matBillBoard._43 = 0.0f;
		m_matBillBoard.Transpose();

		if (m_pTransform)
		{
			if (m_pTransform->HasFlag(SS_TF_ZOOM))
			{
				ssFLOAT4x4X mz;
				mz.Identity();
				mz._11 = m_pTransform->GetScaling().x;
				mz._22 = m_pTransform->GetScaling().y;
				mz._33 = m_pTransform->GetScaling().z;
				m_matBillBoard *= mz;
			}
			if (m_pTransform->HasFlag(SS_TF_MOVE))
			{
				m_matBillBoard._41 = m_pTransform->ViewMatrix()._41;
				m_matBillBoard._42 = m_pTransform->ViewMatrix()._42;
				m_matBillBoard._43 = m_pTransform->ViewMatrix()._43;
			}
		}
		m_shaderModel.Use(m_pShader, m_matBillBoard.m, 4);
	}
}

}
